package com.ymttest.business.service.productdata.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.ymttest.business.service.productdata.ProductOpreate;
import com.ymttest.business.service.productdata.bean.ApplyProductBean;
import com.ymttest.business.service.productdata.bean.ProductBean;
import com.ymttest.utils.EnvSetup;

public class ProductFactory {
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");	
	
	
	public static ProductBean getOnlyProduct(){
		return getOnlyProduct(sellerId,sellerName);
	}
	
	public static ProductBean getOnlyProduct(int sellerId,String sellerName,Map<String,Object> updateMap){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(false)
																.hasNowLive(false)
																.build();
		
		return new ProductFromJSONBean(updateMap).addProduct(applyProductBean);
		
	}
	
	
	
	public static ProductBean getOnlyProduct(int sellerId,String sellerName){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(false)
																.hasNowLive(false)
																.build();
		
		return new ProductFromJSONBean().addProduct(applyProductBean);
		
	}
	
	
	
	public static ProductBean getOnlyProduct(int sellerId,String sellerName,ProductOpreate productOpreate){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(false)
																.hasNowLive(false)
																.build();
		
		return productOpreate.addProduct(applyProductBean);
		
	}
	
	
	public static ProductBean getFutureLiveProduct(int sellerId,String sellerName){
		return getFutureLiveProduct(sellerId,sellerName,null);
		
	}
	
	
	public static ProductBean getFutureLiveProduct(int sellerId,String sellerName,Map<String,Object> updateMap){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(false)
																.hasNowLive(false)
																.futureLiveCount(1)
																.build();
		return new ProductFromJSONBean(updateMap).addProduct(applyProductBean);
		
	}
	
	public static ProductBean getPreviousLiveProduct(int sellerId,String sellerName,Map<String,Object> updateMap){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.preLiveCount(1)
																.hasNowActivity(false)
																.hasNowLive(false)
																.build();
		
		return new ProductFromJSONBean(updateMap).addProduct(applyProductBean);
	}
	
	
	public static ProductBean getLiveProduct(int sellerId,String sellerName){
		return getLiveProduct(sellerId,sellerName,null);
		
	}
	
	public static ProductBean getLiveProduct(int sellerId,String sellerName,Map<String,Object> updateMap){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(false)
																.hasNowLive(true)
																.build();
		return new ProductFromJSONBean(updateMap).addProduct(applyProductBean);
		
	}
	
	
	public static ProductBean getLiveProduct(){
		return getLiveProduct(sellerId,sellerName);
	}
	
	
	
	public static ProductBean getPreviousActivityProduct(int sellerId,String sellerName,Map<String,Object> updateMap){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.preActivityCount(1)
																.hasNowActivity(false)
																.hasNowLive(false)
																.build();
		
		return new ProductFromJSONBean(updateMap).addProduct(applyProductBean);
	}
	
	
	
	
	
	
	
	public static ProductBean getFutureActivityProduct(int sellerId,String sellerName,Map<String,Object> updateProdMap){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.futureActivityCount(1)
																.hasNowActivity(false)
																.hasNowLive(false)
																.build();
		
		return new ProductFromJSONBean(updateProdMap).addProduct(applyProductBean);
	}
	
	
	
	
	public static ProductBean getActivityProduct(int sellerId,String sellerName,Map<String,Object> updateMap){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(true)
																.hasNowLive(false)
																.build();
		
		return new ProductFromJSONBean(updateMap).addProduct(applyProductBean);
	}
	
	
	
	public static ProductBean getActivityProduct(int sellerId,String sellerName){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(true)
																.hasNowLive(false)
																.build();
		
		return new ProductFromJSONBean().addProduct(applyProductBean);
	}
	
	
	
	
	public static ProductBean getTwoSameTimeActivityProduct(int sellerId,String sellerName){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(true)
																.hasNowAnotherActivity(true)
																.hasNowLive(false)
																.build();
		
		return new ProductFromJSONBean().addProduct(applyProductBean);
	}
	
	
	
	
	
	public static ProductBean getActivityProduct(){
		return getActivityProduct(sellerId,sellerName);
	}
	
	
	
	public static ProductBean getLiveAndActivityProduct(int sellerId,String sellerName){
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName)
																.hasNowActivity(true)
																.hasNowLive(true)
																.build();

		return new ProductFromJSONBean().addProduct(applyProductBean);
	}
	
	
	public static ProductBean getLiveAndActivityProduct(){
		return getLiveAndActivityProduct(sellerId,sellerName);
	}
	
	
	
	public static List<ProductBean> getProductWithExistActivity(int sellerId,String sellerName,List<Integer> activityIds,int productCount){
		
		List<ProductBean> ProductBeanList = new ArrayList<>();
		
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName).hasNowActivity(false).hasNowLive(false).build();
		AbstractProductService productService = new ProductFromJSONBean.Builder().ActivityOperate(new ExistActivityService(sellerId,activityIds)).build();
		
		for (int i=0;i<productCount;i++){ProductBeanList.add(productService.addProduct(applyProductBean));}
		
		return ProductBeanList;
		
	}
	
	
	public static List<ProductBean> getProductWithExistStartLive(int sellerId,String sellerName,int liveId,int productCount){
		
		List<ProductBean> ProductBeanList = new ArrayList<>();
		
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(sellerId,sellerName).hasNowActivity(false).hasNowLive(false).build();
		AbstractProductService productService = new ProductFromJSONBean.Builder().LiveOperate(new ExistLiveService(sellerId,Arrays.asList(liveId))).build();
		
		for (int i=0;i<productCount;i++){
			ProductBeanList.add(productService.addProduct(applyProductBean));
		}
		
		return ProductBeanList;
		
	}
	
	
	
	
	
	
	public static void main(String args[]) throws Exception{
		
		ProductFactory.getActivityProduct(288484, "juicyjuicy");
		int x = 20;
		List<String> products  = new ArrayList<>();
		for (int i=0;i<x;i++){
			products.add("\""+ProductFactory.getOnlyProduct(sellerId, sellerName).getProductId()+"\"");
		}
		
		System.out.println(products);
		
		
		
		
		
		
		String sellerName = EnvSetup.getData("productsellername");
		int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
		ProductBean ccc = ProductFactory.getLiveProduct(3383, "wesper");
		
		ProductFactory.getLiveProduct();
		
		
		getProductWithExistActivity(sellerId, sellerName,Arrays.asList(ccc.getProductActivitysBean().getNowActivity()),100);
		
		
		
		
		ApplyProductBean applyProductBean = new ApplyProductBean.Builder(3383,"wepser")
				.preActivityCount(0)
				.hasNowActivity(false)
				.hasNowLive(true)
				.build();

       new ProductFromJSONBean(null).addProduct(applyProductBean);
		
		
		List<String> productList = new ArrayList<>();
		for(int i=0;i<10;i++){
			productList.add(ProductFactory.getActivityProduct(3383, "wepser").getProductId());
		}
		
		
		productList.forEach(ele->System.out.println(ele));
		
		
		
		ProductFactory.getPreviousActivityProduct(3383, "wesper", null);
		
		
		ProductFactory.getTwoSameTimeActivityProduct(3383, "wesper");
		
		ProductFactory.getActivityProduct();
		
		
		List<Integer> activityIds = Arrays.asList(18946);
		int productCount = 10;
		

		
		ProductFactory.getProductWithExistActivity(sellerId,sellerName,activityIds,productCount).forEach(ele->System.out.println(ele.getProductId()));
		
		ProductFactory.getTwoSameTimeActivityProduct(3383, "wesper");
		
		
	}
	
	
	
}
